//
//  CZStatusTooBar.swift
//  WeiBO28
//
//  Created by 飞奔的羊 on 16/5/13.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CZStatusTooBar: UIView {
	//转发
	private lazy var retwwetButton: UIButton = self.addChidButton("timeline_icon_retweet", title: "转发")
	//评论
	private lazy var commenButton: UIButton = self.addChidButton("timeline_icon_comment", title: "评论")
	private lazy var unkikeButton: UIButton = self.addChidButton("timeline_icon_unlike", title: "赞")
	var statusViewModel: CZStatusViewModels? {
	
		didSet{
		
//		 let repostCount = statusViewModsel?.status?.repost_count ?? 0
//			 let commentsCount = statusViewModel?.status?.comments_count ?? 0
//			 let attitudesCount = statusViewModel?.status?.attitudes_count ?? 0
		
			retwwetButton.setTitle(statusViewModel?.retweetCount, forState: .Normal)
			commenButton.setTitle(statusViewModel?.commentConunt, forState: .Normal)
			unkikeButton.setTitle(statusViewModel?.unlikeCount, forState: .Normal)
			
			
		}
	}
	
	override init(frame: CGRect) {
		super.init(frame: frame)
		setUpUI()
	}
	
	required init?(coder aDecoder: NSCoder) {
		fatalError("init(coder:) has not been implemented")
	}
	private func setUpUI() {
		
//		backgroundColor = UIColor.redColor()
	
		let firstLine = addChildLineView()
		let secondLine = addChildLineView()
		retwwetButton.snp_makeConstraints { (make) in
			make.top.equalTo(self)
			make.leading.equalTo(self)
			make.bottom.equalTo(self)
			make.width.equalTo(commenButton)
			
		}
		commenButton.snp_makeConstraints { (make) in
			make.leading.equalTo(retwwetButton.snp_trailing)
			make.top.equalTo(self)
			make.bottom.equalTo(self)
			make.width.equalTo(unkikeButton)
		}
		unkikeButton.snp_makeConstraints { (make) in
			make.top.equalTo(self)
			make.trailing.equalTo(self)
			make.bottom.equalTo(self)
			make.leading.equalTo(commenButton.snp_trailing)
		}
		
		firstLine.snp_makeConstraints { (make) in
			make.centerX.equalTo(retwwetButton.snp_trailing)
			make.centerY.equalTo(self)
		}
		
		secondLine.snp_makeConstraints { (make) in
			make.centerY.equalTo(self)
			make.centerX.equalTo(commenButton.snp_trailing)
		}
		
	}
	/**
	Description
	
	- parameter imageName: 图片名字
	- parameter title:     问你
	*/
	private func addChidButton(imageName: String,title: String) -> UIButton{
		let button = UIButton()
		button.setImage(UIImage(named: imageName), forState: .Normal)
		button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
		
		//1.直接把背景图片作为按钮背景
		//		button.backgroundColor = UIColor(patternImage: UIImage(named: "timeline_card_bottom_background")!)
		//去掉点击后的效果
		button.adjustsImageWhenHighlighted = false
		button.titleLabel?.font = UIFont.systemFontOfSize(15)
		button.setTitle(title, forState: .Normal)
		button.setTitleColor(UIColor.grayColor(), forState: .Normal)
		addSubview(button)
		return button
	}
	private func addChildLineView() ->UIView {
		let view = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
		addSubview(view)
		
		return view
	}

}
